package cn.bytecollege.controller;


import cn.bytecollege.constant.Resource;
import cn.bytecollege.entity.Vip;
import cn.bytecollege.service.VipService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * 修改功能的子功能（单条查询数据功能）的控制器
 * @author Mr.East
 */
@WebServlet(name = "VipFindController",value = "/vipFind")
public class VipFindController extends HttpServlet {
    private VipService vipService = null;
    public VipFindController (){
        vipService = new VipService();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取参数
        String id = request.getParameter("id");
        //封装数据
        Vip vip = new Vip();
        //转型
        Integer vipId = Integer.valueOf(id);
        //调用service方法
        vip = vipService.findByVipId(vipId);
        //封装请求，跳转页面
        request.setAttribute("vip",vip);
        request.getRequestDispatcher(Resource.PAGE_LOCATION+ "/vipUpdate.jsp")
                .forward(request,response);
    }
}
